﻿@using Coslen.Framework.Helpers
@model Coslen.TahorCRM.Domain.Entities.ViewModels.Searching.ContactSearchViewModel

<script language="javascript" type="text/javascript">
    
    function UnselectOtherCheckBoxes(sender) {
        var $self = sender;         // save the current object - checkbox that was clicked. 
        $self.checked = true;     // make the clicked checkbox checked no matter what. 
        $($self).closest('tr')    // find the closest parent tr... 
            .siblings('tr')       // get the siblings of the tr 
            .find(':checkbox').attr('checked', false); // then find the checbox inside each tr and then uncheck it.         
    }

</script>

<h4>Results</h4>

<table class="GenericTable">
    <tr class="GenericTable-HeaderRow">
        <th>
            First Name
        </th>
        <th>
            Last Name
        </th>
        <th>
            Born On
        </th>
        <th>
            Gender
        </th>
        <th>
        </th>
    </tr>
    @foreach (var item in Model.SearchResults.Select((x, i) => new { Data = x, Index = i }))
    {
        <tr class="@( item.Index % 2 == 0 ? "GenericTable-RowAlt" : "GenericTable-Row")">
            <td>
                @Html.DisplayFor(modelItem => item.Data.FirstName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Data.LastName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Data.BornOn)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Data.Gender.Name)
            </td>
            <td>
                @Html.HiddenFor(modelItem => item.Data.ContactId)
                @Html.HiddenFor(modelItem => item.Data.FirstName)
                @Html.HiddenFor(modelItem => item.Data.LastName)
                @Html.HiddenFor(modelItem => item.Data.Title.Name)
            
                <input id="SelectedContact" name="SelectedContact" type="checkbox" onchange="UnselectOtherCheckBoxes(this);" />
            </td>
        </tr>
    }
</table>